package office.stock.persistance;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.TemporalType;

import office.stock.model.Offer;

@Stateless
public class OfferDAO extends AbstractGenericDAO<Offer> {

    //TODO make it configurable
    private final static long OFFER_MAX_AGE = 60*60*1000; // 1 hour
    
    @Override
    public Class<Offer> getEntityClass() {
	return Offer.class;
    }

    @SuppressWarnings("unchecked")
    public List<Offer> getAllActive() {
	Query query = entityManager.createNamedQuery("Offer.getAllActive");
	long current = new Date().getTime();
	query.setParameter("date", new Date(current - OFFER_MAX_AGE), TemporalType.TIMESTAMP);
	return query.getResultList();
    }
}
